/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.pay.db.impl;

//import com.contract.db.IbatisTemplate;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.yunhoo.base.model.AbroadGroupCurrency;
import com.yunhoo.base.model.AbroadGroupGroup;
import com.yunhoo.base.model.PayStyle;
import com.yunhoo.pay.model.AbroadGroupBackorCollar;
import com.yunhoo.pay.model.AbroadGroupCost;
import com.yunhoo.pay.model.Expense;
import com.yunhoo.sys.db.util.IbatisTemplate;
import com.yunhoo.sys.util.common.LoginParam;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 出国差旅费报销单
 *
 * @author Administrator
 */
public class AbroadGroupImpl {

    private static String nameSpace = "abroadGroup.";

    private static Map paramMap() {
        Map map = new HashMap();
        map.put("orgCode", LoginParam.getOrg().getCode());
        return map;
    }

    public static List<Expense> getAbroadPersonList(Map map) {
        return IbatisTemplate.queryForList(nameSpace + "getAbroadPersonList", map);
    }

    //获取主表对象
    public static Expense getAbroadGroup(String str) {
        return (Expense) IbatisTemplate.query(nameSpace + "getAbroadGroup", str);
    }

    //获取费用明细表List
    public static List<AbroadGroupCost> getAbroadGroupCostList(String str) {
        return IbatisTemplate.queryForList(nameSpace + "getAbroadGroupCostList", str);
    }

    //获取退领表List
    public static List<AbroadGroupBackorCollar> getAbroadGroupBackorCollar(String str) {
        return IbatisTemplate.queryForList(nameSpace + "getAbroadGroupBackorCollar", str);
    }

    //保存主表对象
    public static void insertAbroadGroup(Map map) {
        IbatisTemplate.insert(nameSpace + "insertAbroadGroup", map);
    }

    //保存主表对象
    public static void insertAbroadGroup(SqlMapClient client, Map map) throws SQLException {
        client.insert(nameSpace + "insertAbroadGroup", map);
    }

    public static String getAgroupMaxNumber(SqlMapClient client) throws SQLException {
        String ExpenseMaxNumber = (String) client.queryForObject("abroadGroup.maxExpenseAgroupNumber", LoginParam.getOrg().getCode().trim());
        if (ExpenseMaxNumber == null || ExpenseMaxNumber.length() == 0) {
            ExpenseMaxNumber = "000001";
            return ExpenseMaxNumber;
        }
        ExpenseMaxNumber = String.format("%06d%n", Integer.parseInt(ExpenseMaxNumber.trim()) + 1);
        return ExpenseMaxNumber.trim();
    }

    //修改主表对象
    public static void updateAbroadGroup(Map map) {
        IbatisTemplate.update(nameSpace + "updateAbroadGroup", map);
    }

    //修改主表对象
    public static void updateAbroadGroup(SqlMapClient client, Map map) throws SQLException {
        client.update(nameSpace + "updateAbroadGroup", map);
    }

    //保存费用明细list
    public static void insertAbroadGroupCost(Map map) {
        IbatisTemplate.insert(nameSpace + "insertAbroadGroupCost", map);
    }

    //保存费用明细list
    public static void insertAbroadGroupCost(SqlMapClient client, Map map) throws SQLException {
        client.insert(nameSpace + "insertAbroadGroupCost", map);
    }

    //修改费用明细list
    public static void updateAbroadGroupCost(Map map) {
        IbatisTemplate.update(nameSpace + "updateAbroadGroupCost", map);
    }

    //保存退领表List
    public static void insertAbroadGroupBackorCollar(Map map) {
        IbatisTemplate.insert(nameSpace + "insertAbroadGroupBackorCollar", map);
    }

    //保存退领表List
    public static void insertAbroadGroupBackorCollar(SqlMapClient client, Map map) throws SQLException {
        client.insert(nameSpace + "insertAbroadGroupBackorCollar", map);
    }

    //修改退领表List
    public static void updateAbroadGroupBackorCollar(Map map) {
        IbatisTemplate.update(nameSpace + "updateAbroadGroupBackorCollar", map);
    }

    //获取团组成员及明细列表
    public static List<AbroadGroupGroup> getAbroadGroupGroup() {
        return IbatisTemplate.queryForList(nameSpace + "getAbroadGroupGroup", null);
    }

    //获取出国团组code最大值
    public static String getAbroadGroupGroupMaxCode() {
        return (String) IbatisTemplate.query(nameSpace + "getAbroadGroupGroupMaxCode", null);
    }

    //获取币种列表
    public static List<AbroadGroupCurrency> getAbroadGroupCurrency() {
        Map map = paramMap();
        return IbatisTemplate.queryForList(nameSpace + "getAbroadGroupCurrency", map);
    }

    //获取主表单据编号最大值用于 自动生成单据编号
    public static String getMaxNum() {
        return (String) IbatisTemplate.query(nameSpace + "getMaxNum", null);
    }

    //修改单据状态
    public static void updateVouStatus(Map map) {
        IbatisTemplate.update(nameSpace + "updateVouStatus", map);
    }

    //获取支付方式列表
    public static List<PayStyle> getPaystyleli() {
        Map map = paramMap();
        return IbatisTemplate.queryForList(nameSpace + "getPaystyleli", map);
    }
    //获取支付方式列表

    public static List<PayStyle> getPaystyleliNew(String vouType) {
        Map map = paramMap();
        map.put("vouType", vouType);
        return IbatisTemplate.queryForList(nameSpace + "getPaystyleliNew", map);
    }

    public static String getPayStyleName(String code) {
        Map map = paramMap();
        map.put("code", code);
        return (String) IbatisTemplate.query(nameSpace + "getPayStyleName", map);
    }
    //插入出国团组 

    public static void insertAbroadGroupGroup(Map map) {
        IbatisTemplate.insert(nameSpace + "insertAbroadGroupGroup", map);
    }
    //插入出国团组

    public static void insertAbroadGroupGroup(SqlMapClient client, Map map) throws SQLException {
        client.insert(nameSpace + "insertAbroadGroupGroup", map);
    }

    //修改出国团组
    public static void updateAbroadGroupGroup(Map map) {
        IbatisTemplate.update(nameSpace + "updateAbroadGroupGroup", map);
    }

    //修改出国团组
    public static void updateAbroadGroupGroup(SqlMapClient client, Map map) throws SQLException {
        client.update(nameSpace + "updateAbroadGroupGroup", map);
    }

    //删除尚未提交报销单
    public static void deletefrompayVouchers(SqlMapClient client, String str) throws SQLException {
        Map map = paramMap();
        map.put("number", str);
        client.delete(nameSpace + "deletefrompayVouchers", map);
    }

    //删除尚未提交报销单
    public static void deletefrompayVouchers(String str) {
        Map map = paramMap();
        map.put("number", str);
        IbatisTemplate.delete(nameSpace + "deletefrompayVouchers", map);
    }

    public static void deleteAbroadGroupCostLi(String str) {
        Map map = paramMap();
        map.put("number", str);
        IbatisTemplate.delete(nameSpace + "deleteAbroadGroupCostLi", map);
    }

    public static void deleteAbroadGroupCostLi(SqlMapClient client, String str) throws SQLException {
        Map map = paramMap();
        map.put("number", str);
        client.delete(nameSpace + "deleteAbroadGroupCostLi", map);
    }

    public static void deleteAbroadGroupBackLi(String str) {
        Map map = paramMap();
        map.put("number", str);
        IbatisTemplate.delete(nameSpace + "deleteAbroadGroupBackLi", map);
    }

    public static void deleteAbroadGroupBackLi(SqlMapClient client, String str) throws SQLException {
        Map map = paramMap();
        map.put("number", str);
        client.delete(nameSpace + "deleteAbroadGroupBackLi", map);
    }

    public static void main(String args[]) {
        Map map = new HashMap();
        map.put("code", "0008");
        map.put("name", "出国团组008");
        map.put("country", "国家法国");
        map.put("menber", "1231");
        map.put("startDate", new Date());
        map.put("endDate", new Date());
        insertAbroadGroupGroup(map);
        // Expense es = getAbroadGroup("0000101");
        ////System.out.println("es : " + es.getNumber());
//        List li = getAbroadGroupBackorCollar("0000101");
//        //System.out.println("li: " + li.size());
    }

    void tuiling() {
        Map map = new HashMap();
        map.put("number", "0000106");
        map.put("currency", "0001");
        map.put("advance", 3000);
        map.put("sing", "领");
        map.put("amount", 3000);
        insertAbroadGroupBackorCollar(map);
    }

    void cost() {
        Map map = new HashMap();
        map.put("number", "0000106");
        map.put("currency", 3000);
        map.put("stayCost", 3000);
        map.put("foodCost", 3000);
        map.put("mixCost", 3000);
        map.put("personalCost", 3000);
        map.put("trafficCost", 3000);
        map.put("other", 3000);
        insertAbroadGroupCost(map);
    }

    void abroad() {
        Map map = new HashMap();
        map.put("number", "0000106");
        map.put("voudate", "2011");
        map.put("affair", "事由101");
        map.put("person", "00015");
        map.put("auditor", "02005");
        map.put("payer", "02005");
        map.put("memo", "附件张数");
        map.put("voutype", "6");
        map.put("abroadGroup", "0006");
        insertAbroadGroup(map);
    }
}
